//判断一棵二叉树是否为平衡二叉树
class Solution {
    class TreeNode{
       public int val;
       public TreeNode left;
       public  TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }
    }
    public boolean isBalanced(TreeNode root) {
        if(DeepTree(root)>=0) {
            return true;
        }
        return false;
    }
    public  int DeepTree(TreeNode root){
        if(root==null){
            return  0;
        }
        int leftHight=DeepTree(root.left);
        int rightHight=DeepTree(root.right);
        if(leftHight>0
                &&rightHight>0
                && Math.abs(leftHight-rightHight)<=1){
            return Math.max(leftHight,rightHight)+1;
        }
            return -1;
    }
}